package lumis.service.wsrp.producer;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * Entity representing an offered portlet for a specific producer 
 * @version $Revision: 13092 $ $Date: 2011-05-28 18:19:06 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
@Entity
@GenericGenerator(name = "portal-guid", strategy = "lumis.portal.dao.hibernate.GuidGenerator")
@Table(name="lum_WsrpPOfferedPortlet")
@SuppressWarnings("serial")
class OfferedPortlet implements Serializable 
{
	
	@Id
	@GeneratedValue(generator = "portal-guid")
	private String id;
	
	private String interfaceInstanceId; 
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="producerId")
	private ProducerImpl producer;
	
	@OneToMany(mappedBy="originalPortlet", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	private Set<ClonedPortlet> clonedPortlets;
	

	/**
	 * Returns the clonedPortlets for this OfferedPortlet.
	 * @return the clonedPortlets that originated from this offeredPortlets.
	 */
	public Set<ClonedPortlet> getClonedPortlets() 
	{
		return clonedPortlets;
	}

	/**
	 * Sets the clonedPortlets for this OfferedPortlet.
	 * @param clonedPortlets the clonedPortlets that originated from this offeredPortlet.
	 */
	public void setClonedPortlets(Set<ClonedPortlet> clonedPortlets) 
	{
		this.clonedPortlets = clonedPortlets;
	}

	/**
	 * Returns the producer for this OfferedPortlet.
	 * @return producer that owns this OfferedPortlet.
	 */
	public ProducerImpl getProducer() 
	{
		return producer;
	}

	/**
	 * Sets the producer for this OfferedPortlet.
	 * @param producer the producer that owns this offeredPortlet to set.
	 */
	public void setProducer(ProducerImpl producer) 
	{
		this.producer = producer;
	}

	/**
	 * Returns the Id of the OfferedPortlet.
	 * @return id of the current offeredPortlet.
	 */
	public String getId()
	{
		return id;
	}

	/**
	 * Returns the interface instance id for this OfferedPortlet.
	 * @return interfaceInstanceId of this OfferedPortlet.
	 */
	public String getInterfaceInstanceId() 
	{
		return interfaceInstanceId;
	}

	/**
	 * Sets the interface instance id for this OfferedPortlet.
	 * @param interfaceInstanceId the interfaceInstanceId of this OfferedPortlet to set.
	 */
	public void setInterfaceInstanceId(String interfaceInstanceId) 
	{
		this.interfaceInstanceId = interfaceInstanceId;
	}
}
